﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using DomainDriver.DomainModeling.DataProviders;
using DomainDriver.DomainModeling.GenericUnitTesting.Repositories;
using AutomotivePricingModel.ValueObjects.YearlyFinancialAssessments;

namespace AutomotivePricingModel.ValueObjects.UnitTests.YearlyFinancialAssessments
{
    [TestFixture(new object[] { DataSourcePersistenceType.None })]
    [TestFixture(new object[] { DataSourcePersistenceType.File })]
    [TestFixture(new object[] { DataSourcePersistenceType.Database })]
    public class YearlyFinancialAssessmentRepositoryTests : RepositoryTestFixture<TestDomainModel, Guid, YearlyFinancialAssessment>
    {
        public YearlyFinancialAssessmentRepositoryTests(DataSourcePersistenceType persistenceType)
            : base(persistenceType)
        { }

        protected override TestDomainModel CreateDomainModel(DataSourcePersistenceType persistenceType, bool buildModelWithConstraints)
        {
            TestDomainModel model = new TestDomainModel(persistenceType, buildModelWithConstraints);
            return model;
        }

        protected override YearlyFinancialAssessment CreateDomainObject()
        {
            YearlyFinancialAssessment domainObject = new YearlyFinancialAssessment();
            return domainObject;
        }

        protected override void UpdateDomainObject(YearlyFinancialAssessment domainObject, ref bool objectCanBeUpdated)
        {
            objectCanBeUpdated = true;
            domainObject.SetValue(0, 0);
        }

        [Test]
        public void VerifyRepositoryPersistsAllProperties()
        {
            YearlyFinancialAssessmentObjectTests objectTests = new YearlyFinancialAssessmentObjectTests();

            YearlyFinancialAssessment domainObject = CreateDomainObject();
            YearlyFinancialAssessment domainObjectCopy = domainObject.Copy();

            Assert.AreEqual(domainObject, domainObjectCopy);
            Assert.AreNotSame(domainObject, domainObjectCopy);

            DomainModel.YearlyFinancialAssessments().Add(domainObject);

            for (int i = 0; i < objectTests.Modifiers.Count; i++)
            {
                domainObject = DomainModel.YearlyFinancialAssessments().Read(domainObject.Key);

                objectTests.ApplyModifier(domainObject, i);
                domainObjectCopy = domainObject.Copy();

                DomainModel.YearlyFinancialAssessments().Update(domainObject);

                SaveAndReloadDomainModel();

                domainObject = DomainModel.YearlyFinancialAssessments().Read(domainObject.Key);

                Assert.AreEqual(domainObject, domainObjectCopy);
                Assert.AreNotSame(domainObject, domainObjectCopy);
            }
        }
    }
}